<template>
	<view class="page">
		<flowbefore :beflows="beflows" :status="status" :isBtnClick="isBtnClicks" @save="save" @submit="submit" :statusType="statusType">
			<template>
				<view class="padding-bottom-100">
					<form class="flowform">
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>流程标题</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.flowTitle" name="flowTitle" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>单号编号</label></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.billNo" name="billNo" disabled="true" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext" @tap="flowUrgent">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>紧急程度</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.flowUrgent" name="flowUrgent" placeholder="选择" disabled="true" />
								</view>
								<view class="advanceicon iconfont icon-xiangyou"></view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>申请人员</label></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.applyUser" name="applyUser" disabled="true" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext ">
							<view class="formgroup">
								<view class="labletitle"><label>所在职务</label></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.position" name="position" disabled="true" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext margin-top-20">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>会议名称</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.conferenceName" name="conferenceName" placeholder="输入名称" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>会议主题</label></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.conferenceTheme" name="conferenceTheme" placeholder="输入主题" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>会议类型</label></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.conferenceType" name="conferenceType" placeholder="输入类型" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>预计人数</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="number" v-model="meeting.estimatePeople" name="estimatePeople" maxlength="6" placeholder="输入人数"
									 :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>会议室</label></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.conferenceRoom" name="conferenceRoom" placeholder="输入会议室" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>管理人</label></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.administrator" name="administrator" placeholder="输入管理人" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>查看人</label></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.lookPeople" name="lookPeople" placeholder="输入查看人" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>纪要员</label></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.memo" name="memo" placeholder="输入纪要员" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>出席人</label></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.attendees" name="attendees" placeholder="输入出席人" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>申请材料</label></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.applyMaterial" name="applyMaterial" placeholder="输入材料" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>预计金额</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="digit" v-model="meeting.estimatedAmount" name="estimatedAmount" placeholder="输入金额" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>其他出席人</label></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.otherAttendee" name="otherAttendee" placeholder="输入其他出席人" :disabled="disabled" />
								</view>
							</view>
						</view>
						<view class="formlist inputtext" @tap="startDate">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>开始时间</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.startDate" name="startDate" placeholder="选择" disabled="true" />
								</view>
								<view class="advanceicon iconfont icon-xiangyou"></view>
							</view>
						</view>
						<view class="formlist inputtext" @tap="endDate">
							<view class="formgroup border-bottom-E3E3E5">
								<view class="labletitle"><label>结束时间</label><text class="required">*</text></view>
								<view class="controlvalue">
									<input type="text" v-model="meeting.endDate" name="endDate" placeholder="选择" disabled="true" />
								</view>
								<view class="advanceicon iconfont icon-xiangyou"></view>
							</view>
						</view>
						<view class="formlist">
							<view class="formgroup  border-bottom-E3E3E5">
								<view class="labletitletar"><label>会议描述</label></view>
								<view class="controlvalue  uni-textarea">
									<textarea v-model="meeting.describe" name="describe" maxlength="100" :disabled="disabled" placeholder="输入" />
									</view>
							</view>
						</view>
						<view class="formlist inputtext margin-top-20 no-border-bottom" style="height: 100%;">
							<JNPFUpload v-model="fileList" :fileSize='2' :limit='9'></JNPFUpload>
						</view>
						
					</form>
					<view class="height-100"></view>
				</view>
			</template>
		</flowbefore>
		<w-picker :mode="mode" :pickerList="pickerList" ref="picker" :isSearchShow="isSearchShow"></w-picker>
	</view>
</template>

<script>
	import jnpf from '@/common/js/jnpf.js'
	import helper from '@/common/js/helper.js'
	import graceChecker from '@/common/js/graceChecker.js'
	import wPicker from '@/components/w-picker/w-picker.vue'
	import flowbefore from '@/components/work/flow-before.vue'
	
	import config from '@/common/js/config.js'
	let formRule=[
		{name:"flowTitle",checkType:"notnull",checkRule:"",errorMsg:"输入标题"},
		{name:"conferenceName",checkType:"notnull",checkRule:"",errorMsg:"输入会议名称"},
		{name:"startDate",checkType:"notnull",checkRule:"",errorMsg:"选择开始时间"},
		{name:"endDate",checkType:"notnull",checkRule:"",errorMsg:"选择结束时间"},
		{name:"flowUrgent", checkType : "notnull", checkRule:"",  errorMsg:"选择紧急程度"},
		{name:"estimatedAmount", checkType : "money", checkRule:"",  errorMsg:"输入合格的金额"},
		{name:"estimatePeople", checkType : "int", checkRule:"0,6",  errorMsg:"人数应为1-6个字符"},
	];
	export default {
		components: {
			wPicker,
			flowbefore,
		},
		data() {
			return {
				mode:'',//底部弹窗分类
				isSearchShow:false,
				disabled:false,//启用
				status:'',//流程状态
				beflows:{
					operstate:"",
					processId:''
				},
				meeting: {
					billNo: '',
					flowUrgent:'',
					flowTitle:jnpf.userInfo().realName+'的会议申请',
					applyDate: helper.toDate(new Date, 'yyyy-MM-dd'),
					applyUser:jnpf.userInfo().realName+"/"+jnpf.userInfo().account,
					position:jnpf.userInfo().positionName,
					startDate: '',
					endDate: '',
					fileJson:'',
					estimatedAmount:'0',
					estimatePeople:'',
					conferenceName:''
				},
				fileList:[],
				fileJson:[],
				isBtnClicks:false,
				pickerList:[],
				urgentList:[{
					label: "普通",
					value:"1"
				},
				{
					label: "重要",
					value:"2"
				},
				{
					label: "紧急",
					value:"3"
				}],
				statusType:""
			}
		},
		onLoad(e) {
			/* 工作区进入状态 */
			let statusType = uni.getStorageSync("type")
			this.statusType = statusType
			/* 工作区进入状态 End*/
			let flowInfo= JSON.parse(e.flowInfo);
			this.beflows.operstate=flowInfo.operstate;
			if(flowInfo.operstate =='add'){
				this.meeting.flowId=flowInfo.id;
				this.status = 0;
				this.meeting.flowUrgent=helper.getSpinnerNew(this.urgentList,'1');
				helper.ajax({
					url: '/api/System/BillRule/BillNumber/WF_ApplyMeetingNo',
					success: res => {
						this.meeting.billNo=res.data.data;
					}
				});
			}
			if(flowInfo.operstate=='info'){
				this.disabled=flowInfo.disabled;
				this.beflows.processId=flowInfo.id;
				this.status=flowInfo.status;
				helper.ajax({
					url: '/api/WorkFlowForm/ApplyMeeting/' + flowInfo.id,
					success: res => {
						let _meeting=res.data.data;
						this.meeting = _meeting;
						this.meeting.flowUrgent=helper.getSpinnerNew(this.urgentList,_meeting.flowUrgent);
						this.meeting.applyDate=helper.toDate(_meeting.applyDate, 'yyyy-MM-dd');
						this.meeting.startDate = helper.toDate(_meeting.startDate, "yyyy-MM-dd HH:mm");
						this.meeting.endDate = helper.toDate(_meeting.endDate, "yyyy-MM-dd HH:mm");
						if (_meeting.fileJson!="") {
							this.fileList = JSON.parse(_meeting.fileJson);
						}
					}
				});
			}
		},
		methods: {
			flowUrgent(e) {
				if(!this.disabled){
					this.pickerList = this.urgentList;
					this.mode="selector";
					this.$refs.picker.show();
					this.$eventHub.$off('popupmodality');
					this.$eventHub.$on('popupmodality', (data) => {
						this.meeting.flowUrgent = data.result;
						this.$eventHub.$off('popupmodality');
					});
				}
			},
			startDate(e) {
				if(!this.disabled){
					this.mode="dateTime";
					this.$refs.picker.show();
					this.$eventHub.$off('popupmodality');
					this.$eventHub.$on('popupmodality', (data) => {
						this.meeting.startDate = data.result;
						this.$eventHub.$off('popupmodality');
					});
				}
			},
			endDate(e) {
				if(!this.disabled){
					this.mode="dateTime";
					this.$refs.picker.show();
					this.$eventHub.$off('popupmodality');
					this.$eventHub.$on('popupmodality', (data) => {
						this.meeting.endDate = data.result;
						this.$eventHub.$off('popupmodality');
					});
				}
			},
			submit(e){
				this.meeting.fileJson = JSON.stringify(this.fileList)
				let formData=this.meeting;
				if (!graceChecker.check(formData,formRule)) {
					helper.msg(graceChecker.error);
					return
				}
				this.isBtnClicks=true;
				formData.flowUrgent=helper.setSpinnerNew(this.urgentList,formData.flowUrgent);
				formData.status = 0;
				let method = "POST";
				let url = "/api/WorkFlowForm/ApplyMeeting";
				if(formData.id){
					method = "PUT";
					url=url+"/"+formData.id
				}
				formData.applyDate = Date.parse(formData.applyDate);
				formData.startDate = Date.parse(formData.startDate);
				formData.endDate = Date.parse(formData.endDate);
				helper.ajax({
					url: url,
					method:method,
					contentType: "application/json",
					data:formData,
					success: res => {
						helper.msg(res.data.msg, 'success');
						if (this.beflows.operstate=='add') {
							uni.redirectTo({
								url: '../../operate/started/started',
								success: res => {},
								fail: () => {},
								complete: () => {}
							});
						}else{
							uni.navigateBack();
						}
						this.isBtnClicks=false
					}
				});
			},
			save(e){
				this.meeting.fileJson = JSON.stringify(this.fileList)
				let formData=this.meeting;
				if (!graceChecker.check(formData,formRule)) {
					helper.msg(graceChecker.error);
					return
				}
				this.isBtnClicks=true;
				formData.flowUrgent=helper.setSpinnerNew(this.urgentList,formData.flowUrgent);
				formData.status = 1;
				let method = "POST";
				let url = "/api/WorkFlowForm/ApplyMeeting";
				if(formData.id){
					method = "PUT";
					url=url+"/"+formData.id
				}
				formData.applyDate = Date.parse(formData.applyDate);
				formData.startDate = Date.parse(formData.startDate);
				formData.endDate = Date.parse(formData.endDate);
				helper.ajax({
					url: url,
					method:method,
					contentType: "application/json",
					data:formData,
					success: res => {
						helper.msg(res.data.msg, 'success');
						if (this.beflows.operstate=='add') {						
							uni.redirectTo({
								url: '../../operate/started/started',
								success: res => {},
								fail: () => {},
								complete: () => {}
							});
						}else{
							uni.navigateBack();
						}
						this.isBtnClicks=false
					}
				});
			},
		},
	}
</script>

<style>
	.required{
		color: red;
	}
</style>
